<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>main</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../css/oksub.css" media="all"/>
</head>
<style>
    .carType li {
        margin-left: 10px;
    }

    .specific .layui-col-xs6 {
        border: 1px solid #dcaaaa;
        padding-left: 5px;
        height: 400px;
    }
</style>
<body class="console console1 ok-body-scroll" style="width: 80%">
<div class="ok-body home" style="width: 80%;margin-left: 10%">
    <div class="layui-row layui-col-space15">
        <fieldset class="layui-elem-field">
            <legend></legend>
            <div class="">
                <div class="layui-carousel" id="mainCarousel">
                    <div carousel-item style="text-align:center;height: 400px" id="carouselList">
                    </div>
                </div>
            </div>
        </fieldset>
    </div>

    <div class="layui-row layui-col-space15" style="margin: 0 auto">
        <div class="layui-col-md8" style="">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                <legend>当前带领学员</legend>
            </fieldset>

            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <div class="layui-tab-content" style="height: 100px;">
                    <div class="layui-tab-item layui-show">
                        <div id="studentList" lay-filter="studentList"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md4">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                <legend>最新公告</legend>
            </fieldset>
            <div class="layui-card" style="margin-left: 5%;margin-right: 15%">
                <div class="layui-card-body" style="margin-top: 18px;height: 400px;padding-top: 30px" >
                    <h3 class="layui-timeline-title"><span id="noticeTitle"></span></h3>
                    <p id="noticeContent">

                    </p>
                    <br>
                    <span style="float: right;margin-right: 5%" id="noticeTime"></span>

                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<!--js逻辑-->
<script src="../lib/layui/layui.js"></script>
<script src="../js/jquery.min.js"></script>
<script src="../js/application.js"></script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="modify">修改</a>
</script>
<script type="text/javascript">
    var showNotice;
    layui.use(["layer", "carousel", "rate",'table','okLayer'], function () {
        var carousel = layui.carousel;
        var rate=layui.rate;
        var table=layui.table;
        var layer=layui.layer;
        var okLayer=layui.okLayer;
        if(isEmpty(user['coachId'])){
            layer.msg('账号信息异常,请重新登陆', {
                icon: 1,
                time: 1000
            }, function () {
                window.sessionStorage.setItem("user", "");
                window.location = mainUri+"/login.html";
            });
            return
        }
        //获取表格数据
        var studentTable=table.render({
            elem: '#studentList',
            where:{coachId:user['coachId'],studyType:0},
            url: mainUri+"/vChoice/selects", //数据接口
            cols: [[ //表头
                {field: 'studentId', title: 'ID'},
                {field: 'fullname', title: '姓名' },
                {field: 'agender', title: '性别', width:100,templet:function(d){
                        if(d.agender==true){
                            return "男"
                        }else if(d.agender==false){
                            return "女"
                        }
                    } },
                {field: 'phone', title: '电话'},
                {field: 'email', title: '邮箱'},
                {fixed: 'right', title:'操作', toolbar: '#barDemo', width:100}
            ]],
        });

        function editStudent(data) {
            let uri="student/studentEditByCoach.html?"+dataToString(data)
            okLayer.open("信息修改", uri, "40%", "50%", function (layero) {
                let iframeWin = window[layero.find("iframe")[0]["name"]];
            }, function () {
                studentTable.reload({
                    where:{coachId:user['coachId'],studyType:0}
                });
            })
        }
        //监听行工具事件
        table.on('tool(studentList)', function(obj){
            var data = obj.data;
            // console.log(obj)
            if(obj.event === 'modify'){
                editStudent(data)
            }
        });

        /**
         * 轮播
         */
        myAjax(mainUri + "/notice/selects", {limit: 4, isShow: 1, noticeType: 1}, function (d) {
            if (showNotice == null) {
                showNotice = function (noticeId) {
                    if (isNoEmpty(noticeData)) {
                        for (val of noticeData) {
                            if (val['noticeId'] == noticeId) {
                                var content = val['content'].replaceAll('src="http://localhost:8080', 'src="' + MainIP)
                                var width = document.body.clientWidth / 2
                                layer.open({
                                    type: 1,
                                    title: val['title'],
                                    area: [width.toString() + 'px', '500px'],
                                    content: content,
                                    shadeClose: true,
                                    maxmin: true
                                });
                            }
                        }
                    }
                }
            }

            var htmlTop = ' <div class="layui-bg-cyan">\n' +
                '<div onclick="showNotice(\'';
            var htmlContent = '\')"><img width="1525" height="400" src="'
            var htmlBottom = '"></div></div>'
            if (d["code"] == 0) {
                noticeData = d['data'];
                for (val of d['data']) {
                    var html = htmlTop + val['noticeId'] + htmlContent + MainIP + mainUri + val['noticeImg'] + htmlBottom;
                    $("#carouselList").append(html)
                }
            }
            //建造实例
            carousel.render({
                elem: '#mainCarousel'
                , width: '1525px' //设置容器宽度
                , height: '400px'
                , arrow: 'always' //始终显示箭头
                , autoplay: true
            });
        })

        //公告
        myAjax(mainUri+"/notice/selects",{noticeType:0,page:0,limit: 1},function (d) {
            if(d['code']==0){
                $("#noticeTitle").html(d['data'][0]['title'])
                $("#noticeContent").html(d['data'][0]['content'])
                $("#noticeTime").html(d['data'][0]['createDate'])
                $("#noticeContent img").css("max-width","300px")
            }
        })
    });

</script>